package com.pro.controller;

import com.pro.pojo.JsBeforeUser;
import com.pro.pojo.JsMonthCount;
import com.pro.pojo.JsonData;
import com.pro.service.JsBeforeUserService;
import com.pro.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.logging.Logger;

/**
 * ClassName:JsBeforeUserController
 * Package:com.pro.controller
 * Description:
 *
 * @Date:2021/11/13 14:57
 * @Author: ZPT
 */
@RequestMapping("/user")
@RestController
public class JsBeforeUserController {
    @Autowired
    private JsBeforeUserService service;
    @RequestMapping("/getBeforeUserTable")
    public JsonData getBeforeUserTable(){
        return service.getBeforeUserTable();
    }

    @RequestMapping("/updateStatus")
    public JsonData updateStatus(Integer userId,Integer status){
        Integer i = service.updateStatus(userId, status);
        return i>0?JsonData.buildSuccess(i):JsonData.buildError("服务端错误");
    }

    @RequestMapping("/getSearchBeforeUser")
    public JsonData getSearchBeforeUser(String account,String createDate,String nickname){
        return service.getSearchBeforeUser(account,createDate,nickname);
    }

    @RequestMapping("/delBeforeUser")
    public JsonData delBeforeUser(Integer userId){
        Integer i = service.delBeforeUser(userId);
        return i>0?JsonData.buildSuccess(i):JsonData.buildError("服务端错误");
    }

    @RequestMapping("/getRetrievalTable")
    public JsonData getRetrievalTable(String userCode, String consumption, Integer studyDate){
        return service.getRetrievalTable(userCode,consumption,studyDate);
    }

    @RequestMapping("/getinformation")
    public JsonData getinformation(Integer userId){
        JsBeforeUser beforeUser = service.getinformation(userId);
        return beforeUser!=null?JsonData.buildSuccess(beforeUser):JsonData.buildError("服务端错误");
    }
    @RequestMapping("/updateBeforeUser")
    public JsonData updateBeforeUser(JsBeforeUser jsBeforeUser){
        Integer i = service.updateBeforeUser(jsBeforeUser);
        return i>0?JsonData.buildSuccess(i):JsonData.buildError("服务端错误");
    }

    @RequestMapping("/getNonUserDevelopment")
    public JsonData getNonUserDevelopment(String account, String createDate, String nickname,
                                          String userCode, String consumption, Integer studyDate){
        List<JsBeforeUser> list = service.getNonUserDevelopment(account, createDate, nickname,userCode,consumption,studyDate);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }
    @RequestMapping("/getNonUserDevelopmentById")
    public JsonData getNonUserDevelopmentById(Integer userId,String consumption){
        JsBeforeUser beforeUser = service.getNonUserDevelopmentById(userId,consumption);
        return beforeUser!=null?JsonData.buildSuccess(beforeUser):JsonData.buildError("服务端错误");
    }
    @RequestMapping("/getZeroConsumeUser")
    public JsonData getZeroConsumeUser(){
        List<JsBeforeUser> userList = service.getZeroConsumeUser();
        return userList!=null?JsonData.buildSuccess(userList):JsonData.buildError("服务端错误");
    }
    @RequestMapping("/count")
    public JsonData count(){
        int count = service.count();
        return count>=0?JsonData.buildSuccess(count):JsonData.buildError("服务端错误");
    }
    @RequestMapping("/countMonth")
    public JsonData countMonth(){
        List<JsMonthCount> list = service.countMonth();
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务端错误");
    }
    @RequestMapping("/yesterdayAddCount")
    public JsonData yesterdayAddCount(){
        int yesterdayAddCount = service.yesterdayAddCount();
        return yesterdayAddCount>=0?JsonData.buildSuccess(yesterdayAddCount):JsonData.buildError("服务端错误");
    }
    @RequestMapping("/todayAddCount")
    public JsonData todayAddCount(){
        int todayAddCount = service.todayAddCount();
        return todayAddCount>=0?JsonData.buildSuccess(todayAddCount):JsonData.buildError("服务端错误");
    }
    @RequestMapping("/monthAddCount")
    public JsonData monthAddCount(){
        int monthAddCount = service.monthAddCount();
        return monthAddCount>=0?JsonData.buildSuccess(monthAddCount):JsonData.buildError("服务端错误");
    }

}
